//
//  ZZProductDetailTableViewCell.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/18.
//

#import "ZZProductDetailTableViewCell.h"

@interface ZZProductDetailTableViewCell ()

@property (nonatomic, strong) UIImageView * imgView;
@property (nonatomic, strong) UILabel * titLabel;
@property (nonatomic, strong) UILabel * priceLabel;
@property (nonatomic, strong) UILabel * depositLabel;

@end

@implementation ZZProductDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];

        self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 195)];
        self.imgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.imgView];

        self.titLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPadding, CGRectGetMaxY(self.imgView.frame) + 30, kScreenWidth - kPadding * 2, 52)];
        self.titLabel.textColor = k333Color;
        self.titLabel.font = [UIFont boldSystemFontOfSize:20];
        self.titLabel.numberOfLines = 2;
        [self.contentView addSubview:self.titLabel];
        
        self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPadding, CGRectGetMaxY(self.titLabel.frame) + 15, 120, 28)];
        self.priceLabel.textColor = kRGBAColor(0xFF0000, 1);
        self.priceLabel.font = [UIFont boldSystemFontOfSize:26];
        [self.contentView addSubview:self.priceLabel];
        
        self.depositLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kPadding - 100, self.priceLabel.center.y - 6, 100, 16)];
        self.depositLabel.textColor = k999Color;
        self.depositLabel.font = [UIFont systemFontOfSize:14];
        self.depositLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.depositLabel];
        
    }
    return self;
}

-(void)setCellData:(ZZProductModel *)model {
    NSArray * imgs = [model.imgs componentsSeparatedByString:@","];
    if (imgs.count > 0) {
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:imgs[0]]];
    }
    self.titLabel.text = model.goodsTitle;
    self.depositLabel.text = [NSString stringWithFormat:@"押金:￥%d", model.payAmount];
    
    NSString *string = [NSString stringWithFormat:@"￥%.2f/天", model.orderFee];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange helloRange = [string rangeOfString:@"￥"];
    [attributedString setAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]} range:helloRange];
    NSRange worldRange = [string rangeOfString:@"/天"];
    [attributedString setAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]} range:worldRange];
    self.priceLabel.attributedText = attributedString;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
